#include <dirent.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <assert.h>
#include <unistd.h>
#include <fcntl.h>  
#include <netinet/in.h>
#include <getopt.h>
#include <netdb.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <thread>
#include <string>
#include <vector>

namespace zzyserver
{
	#define SERVER_PORT 12345
	#define MAX_PORT_NUM 65535
	#define FILE_SIZE 500 
	#define MAX_SENDLENGTH 100000
	#define BUFFER_SIZE 1024
	#define MAX_CONNETCION_COUNT 20
	#define DEBUG_LOG 0
	#define SLEEPUS 1000
	struct TCP_STRUCT_DATA
	{
		int m_cmd;
		int m_data_len;
	};

	enum TCP_CMD
	{
		GET_FILE = 0,
		GET_DIR = 1,
		//...
	};
	struct Opt
	{
	public:
		std::string ip;
		int port;
		bool hidden;
		bool show;
		std::string outfilename;
		std::string sourcename;
		Opt():ip(std::string("")),outfilename(std::string("")),sourcename(std::string("")){}
	};
	using Popt = Opt*;
	class MyTools
	{
		public:
		int judgefile(std::string filepath);
		long get_file_size(std::string file_name);
		int TraverseDir(std::string direntName, int level, bool flag);
		bool parseopt(int argc, char *argv[], Popt opt, struct option *long_options, std::string shortopts, bool fserver);
		bool is_ipv4_addr(std::string ip);
		int is_exist_file(std::string filepath, std::string filename);
    	bool judgepath(const std::string& path);
	};
}